package org.collection.newcollection;

import java.util.Iterator;
import java.util.Set;

import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;

public class MultisetTest {

	public static void main(String[] args) {
		//-----------------------------------------------
		// HashMultiset
		System.out.println("HashMultiset");
		Multiset<String> multiset = HashMultiset.create();
		multiset.add("A1");
		multiset.add("A1");
		multiset.add("A2");
		multiset.add("A3");
		
		multiset.add("A1");
		multiset.add("B1");
		multiset.add("C1");
		multiset.add("C1");
		multiset.add("C1");
		
		System.out.println("C1:" + multiset.count("C1"));
		System.out.println("size:" + multiset.size());
		System.out.println("difference-size : " + multiset.elementSet().size());
		
		Iterator<String> it = multiset.iterator();
		while (it.hasNext()) {
			String element = it.next();
			System.out.print(element + " ");
		}
		System.out.println();
		
		multiset.setCount("C1", 0);
		multiset.remove("A1");
		Set<Multiset.Entry<String>> hashMultisetEntrySet = multiset.entrySet();
		for (Multiset.Entry<String> entry : hashMultisetEntrySet) {
			String em = entry.getElement();
			System.out.print(em + ":" + entry.getCount() + " ");
		}
		System.out.println();
		
		
		//-----------------------------------------------
		// HashMultiset
	}
}
